// 工具类
console.log("3RBushUtil");
let utils = data["utils"];
let RBushItem = data["RBushItem"];
var RBU = {
  findItem: function (item, items, equalsFn) {
    if (!equalsFn) return items.indexOf(item);
    for (var i = 0; i < items.length; i++)
      if (equalsFn(item, items[i])) return i;
    return -1;
  },
  calcBBox: function (node, toBBox) {
    RBU.distBBox(node, 0, node.children.length, toBBox, node);
  },
  distBBox: function (node, k, p, toBBox, destNode) {
    destNode || (destNode = RBU.createNode(null));
    destNode.minX = 1 / 0;
    destNode.minY = 1 / 0;
    destNode.maxX = -(1 / 0);
    destNode.maxY = -(1 / 0);
    for (var child, i = k; i < p; i++) {
      child = node.children[i];
      RBU.extend(destNode, node.leaf ? toBBox(child) : child);
    }
    return destNode;
  },
  extend: function (a, b) {
    a.minX = Math.min(a.minX, b.minX);
    a.minY = Math.min(a.minY, b.minY);
    a.maxX = Math.max(a.maxX, b.maxX);
    a.maxY = Math.max(a.maxY, b.maxY);
    return a;
  },
  compareNodeMinX: function (a, b) {
    return a.minX - b.minX;
  },
  compareNodeMinY: function (a, b) {
    return a.minY - b.minY;
  },
  bboxArea: function (a) {
    return (a.maxX - a.minX) * (a.maxY - a.minY);
  },
  bboxMargin: function (a) {
    return a.maxX - a.minX + (a.maxY - a.minY);
  },
  enlargedArea: function (a, b) {
    return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) * (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
  },
  intersectionArea: function (a, b) {
    var minX = Math.max(a.minX, b.minX),
      minY = Math.max(a.minY, b.minY),
      maxX = Math.min(a.maxX, b.maxX),
      maxY = Math.min(a.maxY, b.maxY);
    return Math.max(0, maxX - minX) * Math.max(0, maxY - minY);
  },
  contains: function (a, b) {
    return a.minX <= b.minX && a.minY <= b.minY && b.maxX <= a.maxX && b.maxY <= a.maxY;
  },
  intersects: function (a, b) {
    return b.minX <= a.maxX && b.minY <= a.maxY && b.maxX >= a.minX && b.maxY >= a.minY;
  },
  createNode: function (children) {
    return {
      children: children,
      height: 1,
      leaf: !0,
      minX: 1 / 0,
      minY: 1 / 0,
      maxX: -(1 / 0),
      maxY: -(1 / 0)
    };
  },
  multiSelect: function (arr, left, right, n, compare) {
    for (var mid, stack = [left, right]; stack.length;) {
      right = stack.pop();
      left = stack.pop();
      if (!(right - left <= n)) {
        mid = left + Math.ceil((right - left) / n / 2) * n;
        quickselect(arr, mid, left, right, compare);
        stack.push(left, mid, mid, right);
      }
    }
  }
}

return {
  "utils": utils,
  "RBushItem": RBushItem,
  "RBU": RBU,
}